
#import "Controller.h"
#import "UNIXobject.h"
#import "Indicator.h"
#import <strings.h>
#import <streams/streams.h>
#import <appkit/Text.h>
#import <appkit/TextField.h>
#import <appkit/ScrollView.h>
#import <appkit/Application.h>
#import <appkit/Window.h>

@implementation Controller

- appDidInit:sender
{
	time=10;
	strcpy(command,"");
	[unixObject setDelegate:self];
	[commandField selectText:self];
	[self setInterval];
	return self;
}

- setCommand:sender
{
	strcpy(command,[sender stringValue]);
	[commandField selectText:self];
	[self doCommand];
	return self;
}

- setTime:sender
{
	time=[sender floatValue];
	[commandField selectText:self];
	[self setInterval];
	return self;
}

- (void)doCommand
{
	if (strcmp(command,"")) {
		[theIndicator flash];
		[unixObject execute:command];
	}
	return;
}

- returnOutput:(NXStream *)theStream
{
	[[outputText docView] readText:theStream];
	return self;
}

void repeat (DPSTimedEntry timedEntry, double timeNow, void *data)
{
	[(id)data doCommand];
}


- setInterval
{
   	void repeat ();
	if (timer) DPSRemoveTimedEntry(timer);
	timer=DPSAddTimedEntry(time,&repeat,self,NX_BASETHRESHOLD);
	return self;
}

- windowWillResize:sender toSize:(NXSize *)size
{
	if (size->width < 348)
		size->width=348;
	if (size->height < 166)
		size->height=166;
	return self;
}
@end
